package com.pigdogbay.anagramsolver.model;


import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import com.pigdogbay.anagramsolver.AnagramSolverApplication;
import com.pigdogbay.anagramsolver.R;
import android.app.Activity;

public class DictionaryData implements IDictionaryModel{
	private Activity _Activity;	

	public DictionaryData(Activity activity)
	{
		_Activity = activity;
	}

	@Override
	public List<String> getDictionary() {
		AnagramSolverApplication app = (AnagramSolverApplication) _Activity.getApplication();
		return app.getDicitionary();
	}
	@Override
	public void setDictionary(List<String> dictionary) {
		AnagramSolverApplication app = (AnagramSolverApplication) _Activity.getApplication();
		app.setDictionary(dictionary);
	}
	@Override
	public List<String> loadStandardDictionary() throws IOException {
		return loadDictionary(R.raw.standard);
	}

	private List<String> loadDictionary(int id) throws IOException
	{
		InputStream inputStream = null;
		try
		{
			inputStream = _Activity.getResources().openRawResource(id);
			return DictionaryReader.LoadDictionary(inputStream);
		} 
		finally
		{
			if (inputStream != null)
			{
				inputStream.close();
			}
		}
		
	}

}
